package com.example.xm.service.impl;

import com.example.xm.entity.Gedan;
import com.example.xm.entity.Yinyue;
import com.example.xm.mapper.DingcaiMapper;
import com.example.xm.mapper.GedanMapper;
import com.example.xm.mapper.YinyueMapper;
import com.example.xm.service.IGedanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GedanServiceImpl implements IGedanService {
@Autowired
private GedanMapper gedanMapper;
@Autowired
private DingcaiMapper dingcaiMapper;
@Autowired
private YinyueMapper yinyueMapper;
    @Override
    public int add(Gedan gedan) {
        return gedanMapper.insert(gedan);
    }

    @Override
    public List<Gedan> list(Integer uid) {
        List<Gedan> list = gedanMapper.list(uid);
        for (Gedan gedan : list) {
            Integer num=  dingcaiMapper.getNum(gedan.getId());
            gedan.setNum(num);
        }
        return list;
    }

    @Override
    public Gedan getData(Integer id) {
        Gedan gedan = gedanMapper.selectByPrimaryKey(id);
      List<Yinyue> list=  yinyueMapper.selectListByGid(gedan.getId());
      Integer t=0;
        for (Yinyue yinyue : list) {
            t+=yinyue.getNum();
        }
        gedan.setNum(t);
        gedan.setList(list);
        return gedan;
    }
}
